import { _decorator, Canvas, director, instantiate, Label, Prefab, resources, tween, Vec3 } from 'cc';
import { BaseClass } from './BaseClass';
import { ResManager } from './ResManager';
import { AbNames } from '../../../Game/Scripts/Config/ResConfig';

/**
 * 提示模块
 */
export class GameTip extends BaseClass {
    private static _inst: GameTip;
    public static get inst(): GameTip {
        if (this._inst == null) {
            this._inst = new GameTip();
        }

        return this._inst;
    }

    constructor() {
        super()
    }

    /**
     * 显示提示条
     * @param str 
     */
    public showTip(str: string) {
        let pre = ResManager.inst.getAsset(AbNames.Common, 'Prefabs/GameTip', Prefab);
        let parent = director.getScene().getComponentInChildren(Canvas).node;
        let node: any = instantiate(pre);
        node.parent = parent;

        let lab = node.getChildByPath('root/bg/Label').getComponent(Label);
        lab.string = str;
        tween()
            .target(node)
            .by(1, { position: new Vec3(0, 80, 0) })
            .removeSelf()
            .start()
    }
}